﻿<!--Write a function that checks if a given object contains a given property
-->


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>CheckIfContainsProperty</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <div id="js-console"></div>
    
    <script src="scripts/js-console.js"></script>
    <script>

        var arr = new Array(1, 2, 1, 3, 2, 4); //array is object
        var point1 = { X: 0, Y: 3 };

        var prop = "length";
        var hasProp = hasProperty(arr, prop); //check if array has length
        jsConsole.writeLine("Array has property " + prop + " :" + hasProp);

        hasProp = hasProperty(point1, prop);//check if point has length
        jsConsole.writeLine("Point has property " + prop + " :" + hasProp);

        prop = "X";
        hasProp = hasProperty(arr, prop); //check if array has property X
        jsConsole.writeLine("Array has property " + prop + " :" + hasProp);

        hasProp = hasProperty(point1, prop); //check if array has property X
        jsConsole.writeLine("Point has property " + prop + " :" + hasProp);

        function hasProperty(obj, prop) {
            if (obj.hasOwnProperty(prop)) {
                return true;
            }
            return false;
        }

    </script>
</body>
</html>